﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace CommonLib.Audio {

	public class AudioSystem : IAudioSystem
	{

		private AudioManagerBase Manager { get; set; }

		//当前需要保存的AudioSub的字段名
		public List<string> SaveList { get; private set; }
		//子播放系统引索
		public Dictionary<string, AudioSubManager> Group => m_AudioSubManagerDic;
		private Dictionary<string, AudioSubManager> m_AudioSubManagerDic = new Dictionary<string, AudioSubManager>();

		public AudioSource GetAudioSourceByLabel(string group, string label)
		{
			throw new System.NotImplementedException();
		}

		public float GetVolumeByLabel(string group, string label)
		{
			throw new System.NotImplementedException();
		}

		/*
		public void Init(AudioManagerBase manager)
		{
			throw new System.NotImplementedException();
		}
		*/
		public void Init(AudioManagerBase manager, List<string> groupNeedSave = null)
		{
			Manager = manager;

			//接收或创建List
			if (null == groupNeedSave)
				SaveList = new List<string>(0);
			else
				SaveList = groupNeedSave;
		}

		public bool IsPlaying(string group, string label)
		{
			throw new System.NotImplementedException();
		}

		public void Play(string group, string label, AudioDataBase data, float fadein, float fadeout)
		{
			GetSubManager(group).Play(label, data, fadein, fadeout);
		}

		public void Stop(string group, string label, float fadeout)
		{
			throw new System.NotImplementedException();
		}

		public void StopAll(float fadeout)
		{
			throw new System.NotImplementedException();
		}

		public void StopGroup(string group, float fadeout)
		{
			throw new System.NotImplementedException();
		}

		public void StopGroupAll(string group, float fadeout)
		{
			throw new System.NotImplementedException();
		}


		//私有
		private AudioSubManager GetSubManager(string label)
		{
			//检查字典中是否含有SubManager如果没有则创建一个
			if (!Group.ContainsKey(label))
			{
				GameObject subGo = new GameObject(label);
				subGo.transform.parent = Manager.gameObject.transform;
				AudioSubManager subManager = subGo.AddComponent<AudioSubManager>();
				subManager.Init();
				Group.Add(label, subManager);
				return subManager;
			}
			else
				return Group[label];
		}
	}
}